*** Barberia et al. (2022)
*** Brazilian Political Science Review
*** "The Relationship between Ideology and COVID-19 Deaths: What We Know and What We Still Need to Know"
*** Figure 9

clear

use "Data/voteshare.dta", clear

* Data management 

reshape wide proporçãodevotosrecebidos, i(município) j(turno)
merge 1:m uf using "Data/InLoco"

encode uf, g(state)

* Cleaning the data

drop _merge city

order date_start wy uf state município isolated proporçãodevotosrecebidos2 proporçãodevotosrecebidos1

label var proporçãodevotosrecebidos1 "Bolsonaro vote share 2018 election 1st round"
label var proporçãodevotosrecebidos2 "Bolsonaro vote share 2018 election 2nd round"
rename proporçãodevotosrecebidos1 bolsonarovotes1stround
rename proporçãodevotosrecebidos2 bolsonarovotes2ndround

* Average Home Permanence in the capitals where Bolsonaro won vs where he lost in the 2018 Elections

* First round
sort date_start
by date_start: egen mean_bolsonarovotes1stround_w50 = mean(isolated) if bolsonarovotes1stround >= 0.50
sort date_start
by date_start: egen mean_bolsonarovotes1stround_l50 = mean(isolated) if bolsonarovotes1stround < 0.50

* Second round
sort date_start
by date_start: egen mean_bolsonarovotes2ndround_w50 = mean(isolated) if bolsonarovotes2ndround >= 0.50
sort date_start
by date_start: egen mean_bolsonarovotes2ndround_l50 = mean(isolated) if bolsonarovotes2ndround < 0.50

* Collapse data set by the Average Home Permanence in State Capitals where Bolsonaro won and lost majority of votes in the 2018 elections

collapse (mean) mean_bolsonarovotes1stround_w50 mean_bolsonarovotes1stround_l50 /*
			 */ mean_bolsonarovotes2ndround_w50 mean_bolsonarovotes2ndround_l50, by(date_start)
			 
* Figure 9
	
tsset date_start

label variable date_start "Date"
label variable mean_bolsonarovotes1stround_w50 "Bolsonaro won ({&ge} 50% of the votes)"
label variable mean_bolsonarovotes1stround_l50 "Bolsonaro lost ({&lt} 50% of the votes)"

label variable mean_bolsonarovotes2ndround_w50 "Bolsonaro won ({&ge} 50% of the votes)"
label variable mean_bolsonarovotes2ndround_l50 "Bolsonaro lost ({&lt} 50% of the votes)"

* Figure 9. Panel A

tsline mean_bolsonarovotes1stround_w50 mean_bolsonarovotes1stround_l50, xlabel(,angle(75))leg(pos(6) col(1) size(small)) /*
	*/ ytitle("Average Home Permanence (%)", size(small)) lwi(thick thick) lpatter(solid solid) /*
	*/ tline(11mar2020, lcolor(red)) ttext(.6 11mar2020 "WHO Pandemic", placement(north) color(red) size(small)) /*
	*/ title("First round") xtitle(,size(small)) lcolor(black*1.8 black*0.3) 
	
graph export "Figures/figure9_panela.png", replace
	
* Figure 9. Panel B

tsline mean_bolsonarovotes2ndround_w50 mean_bolsonarovotes2ndround_l50, xlabel(,angle(75)) leg(pos(6) col(1) size(small)) /*
	*/ ytitle("Average Home Permanence (%)", size(small)) lwi(thick thick) lpatter(solid solid) /*
	*/ tline(11mar2020, lcolor(red)) ttext(.6 11mar2020 "WHO Pandemic", placement(north) color(red) size(small)) /*	
	*/ title("Second round") xtitle(,size(small)) lcolor(black*1.8 black*0.3) 
	
graph export "Figures/figure9_panelb.png", replace
	
